/*
 * author      : dormi330
 * date        : 2018/6/28
 * description : 统一 http 响应
 */

package org.wzq.learn;

import com.google.gson.Gson;

public class HttpResponsePayload<T> {
    private String requestId;
    private String code;
    private String msg;
    private T payload;

    public HttpResponsePayload(String reqId, T payload) {
        requestId = reqId;
        this.code = "0";
        this.msg = null;
        this.payload = payload;
    }

    public HttpResponsePayload(String reqId, String code, String msg) {
        requestId = reqId;
        this.code = code;
        this.msg = msg;
        this.payload = null;
    }

    @Override
    public String toString() {
        return new Gson().toJson(this);
    }

    // === setter/getter ===

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getPayload() {
        return payload;
    }

    public void setPayload(T payload) {
        this.payload = payload;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
}
